home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-29 | 5.0 KB | 200 lines | [TEXT/KAHL] |
- #if defined( __SC__)
- #include <pascal.h>
- #endif
-
- #include <Types.h>
- #include <SegLoad.h>
- #include <Files.h>
- #include <Resources.h>
- #include <Memory.h>
- #include <Devices.h>
- #include <Palettes.h>
- #include <Timer.h>
-
- #include "general.h"
- #include "macutilities.h"
- //
- // 940207: 'framerate_of_main_monitor()' doesn't seem to work any more.
- // I don't have time to delve deep into it, so I simply replace it by
- // a version which is not 100% guaranteed to work.
- //
- // 940209: The problem seemed to be related to a damaged copy of TPM or
- // one of its translators. After reinstalling SC++ 6.0.1 from scratch
- // everything seems to work again (take that back; the crashes reappeared
- // within a day) (940216: It seems to work perfectly now)
- //
- // 940122: framerate_of_main_monitor has been moved to 'vretrace.cp'
- //
- void set_settingsfile( char *settingsfile, const OSType creator)
- {
- //
- // 930408: first check whether a parameter was passed to this file.
- //
- // 950309: CountAppFiles is unsupported in the Universal Interfaces
- // The new 'SegLoad.h' states:
- //
- // CountAppFiles, GetAppFiles, ClrAppFiles, GetAppParms, and
- // getappparms are obsolete. They are still supported for 68K
- // apps (if OBSOLETE is defined), but they are not supported
- // for PowerPC apps. Use AppleEvents to determine which files
- // are to be opened or printed from the Finder.
- //
- // We hack around this. This implies that our no-nonsense interface
- // to the experiments doesn't work on a PPC!!
- //
- #ifndef __MWERKS__
- short message;
- short count;
-
- CountAppFiles( &message, &count);
-
- if( count == 0)
- {
- #endif
- //
- // check for the existence of the options file first. If it doesn't exist it can be
- // recreated from 'TEXT' resource #128.
- //
- CtoPstr( settingsfile);
- OSErr foutje = Create( (const unsigned char *)settingsfile, 0, creator, 'TEXT');
-
- if( foutje == noErr)
- {
- short filerefno;
- foutje = FSOpen( (const unsigned char *)settingsfile, 0, &filerefno);
-
- if( foutje == noErr)
- {
- Handle default_text = GetResource( 'TEXT', 128);
- if( default_text == 0)
- {
- report_error_and_exit( "TEXT resource 128 could not be found");
- }
- long numbytes = GetHandleSize( default_text);
- HLock( default_text);
- foutje = FSWrite( filerefno, &numbytes, StripAddress( *default_text));
- ReleaseResource( default_text);
-
- if( foutje != noErr)
- {
- report_error_and_exit( "error writing default parameter file");
- }
- foutje = FSClose( filerefno);
- if( foutje != noErr)
- {
- report_error_and_exit( "error closing default parameter file");
- }
- }
- }
- //
- // Convert back to C string; the main app expects it to be unchanged
- //
- PtoCstr( (unsigned char *)settingsfile);
- #ifndef __MWERKS__
- } else {
- if( count == 1)
- {
- AppFile thefile;
- GetAppFiles( 1, &thefile);
- ClrAppFiles( 1);
-
- if( thefile.fType != 'TEXT')
- {
- report_error_and_exit( "Sorry, can only open TEXT files");
- }
- SetVol( 0, thefile.vRefNum);
- //
- // copy Pascal string in 'thefile.fName' as C string to 'settingsfile':
- //
- const int numbytes = thefile.fName[ 0];
-
- for( int i = 0; i < numbytes; i++)
- {
- settingsfile[ i] = thefile.fName[ i + 1];
- }
- settingsfile[ numbytes] = 0;
- } else {
- //
- // More than one file was passed to the application: we don't support that.
- //
- report_error_and_exit(
- "Sorry, only one file at a time can be passed to this application"
- );
- }
- }
- #endif
- }
-
- int TwoBitColorMode( const GDHandle thedevice)
- {
- int result = 0;
-
- const int current_type = (**thedevice).gdType;
-
- if( current_type == clutType)
- {
- //
- // bit # value contents:
- // 0 0x0001 set if device supports color
- // 13 0x2000 set if device is a screen device
- // 15 0x8000 set if device is active
- //
- // check for 2-bit color mode
- //
- result = HasDepth( thedevice, 2, 0x0001, 0x0001);
- }
- return result;
- }
-
- int GetIxDevice( const int monitorno, GDHandle &theGDevice, short &themode, short bitDepth)
- {
- theGDevice = GetDeviceList();
- themode = 0;
-
- int current_index = 1;
-
- while( (theGDevice != 0) && (current_index < monitorno))
- {
- theGDevice = GetNextDevice( theGDevice);
- current_index += 1;
- }
- if( theGDevice != 0)
- {
- //
- // monitor exists; check its characteristics
- //
- const int current_type = (**theGDevice).gdType;
-
- if( current_type == clutType)
- {
- //
- // bit # value contents:
- // 0 0x0001 set if device supports color
- // 13 0x2000 set if device is a screen device
- // 15 0x8000 set if device is active
- //
- // check for depth
- //
- themode = HasDepth( theGDevice, bitDepth, 0x0001, 0x0001);
- }
- } else {
- //
- // monitor specified doesn't exist
- //
- }
- return( themode != 0);
- }
-
- void load_clut( const int resno)
- {
- CTabHandle clutHandle = (CTabHandle)GetResource( 'clut', resno);
- if( clutHandle != 0L)
- {
- HLock( (Handle)clutHandle);
- const short numEntries_minus_1 = (**clutHandle).ctSize;
- SetEntries( 0, numEntries_minus_1, (**clutHandle).ctTable);
- HUnlock( (Handle)clutHandle);
- }
- ReleaseResource( (Handle)clutHandle);
- }
-